package com.sniper.phoenix;

import java.sql.*;

/**
 * Created by suzhen on 2017/6/27.
 */
public class PhoenixHolder {


    String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
    String url = "jdbc:phoenix:thin:url=http://192.168.190.118:8765;serialization=PROTOBUF";
    Connection conn;

    public void conn() throws ClassNotFoundException, SQLException {
        //Class.forName(driver);
        conn = DriverManager.getConnection(url);
        System.out.println("Connect HBase success..");
    }

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        PhoenixHolder phoenixHolder = new PhoenixHolder();
        phoenixHolder.conn();

        PreparedStatement statement = phoenixHolder.conn.prepareStatement("SELECT * FROM \"phoenix_2\"");

        ResultSet rs = statement.executeQuery();


        ResultSetMetaData metaData =  rs.getMetaData();
        int columnCount = metaData.getColumnCount();
        while (rs.next()) {
            for (int i = 0; i < columnCount; i++) {
                System.out.println(rs.getString(i + 1));
            }
        }
        rs.close();
        statement.close();
        phoenixHolder.conn.close();
    }
}
